<template>
  <div class="home">
    <h1>Auto Card</h1>
    <h2>输入学号：</h2>
    <van-field v-model="unum" placeholder="请输入学号" />
    <van-button class="btn" @click="onLogin" color="linear-gradient(to right, #ff6034, #ee0a24)">登  入</van-button>
  </div>
</template>
<script>
export default {
    data(){
      return {
        unum: ''
      }
    },
    methods:{
      onLogin(){
        if(this.unum == ''){
          this.$notify({ type: 'warning', message: '请输入学号！' });
          return
        }
        this.axios.get('getuserv',{
          params:{
            uid: this.unum
          }
        }).then((res)=>{
          // 记录登入的id
          this.$store.commit('setUid',this.unum)
          if(res.data){
            // 查有数据,user:{...},uid:...
            this.$store.commit('setUser',res.data)
            this.$notify({ type: 'success', message: '登录成功！' })
            this.$router.push('/')
          }else{
            // 查无数据,user:null,uid:...
            this.$notify({ type: 'warning', message: '完善信息！' })
            this.$router.push('/adduser')
          }
        })
      }
    }
}
</script>
<style lang="scss" scoped>
.home{
  margin: 20px;
}
.btn{
  margin-top: 20px;
  width: 100%;
}
</style>